package com.lyd.lydblog.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/h")
@Controller
public class HelloController {

	/**
	 * 值传递
	 * @param request
	 * @return
	 */
	@RequestMapping("/hello")
	@ResponseBody
	public String sayHello(HttpServletRequest request){
		Map userMap = new HashMap();
		userMap.put("name", "张三");
		userMap.put("age", "13");
		request.setAttribute("user", userMap);
		return "hello world3";
	}
	/**
	 * 页面跳转
	 * @param request
	 * @return
	 */
	@RequestMapping("/user")
	public String getUser(HttpServletRequest request){
		Map userMap = new HashMap();
		userMap.put("name", "张三");
		userMap.put("age", "13");
		request.setAttribute("user", userMap);
		request.setAttribute("context", "这是我的信息");
		return "user";
	}
	
	/**
	 * 数据库访问
	 * @param request
	 * @return
	 */
	@RequestMapping("/users")
	public String getUsers(HttpServletRequest request){
		
		Map userMap = new HashMap();
		userMap.put("name", "张三");
		userMap.put("age", "13");
		request.setAttribute("user", userMap);
		request.setAttribute("context", "这是我的信息");
		return "user";
	}
}
